package demo.io;

import java.io.BufferedInputStream;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;

/**
 * 旧的IO读取文件方式
 *
 * @author liuteng
 * @date 2017/8/8 10:02
 */
public class OldIO {
    public static void main(String[] args) {
        InputStream inputStream = null;
        try {
            inputStream = new BufferedInputStream(new FileInputStream("doc/io.txt"));
            byte[] buf = new byte[1024];
            int bytesRead = inputStream.read(buf);
            while (bytesRead != -1) {
                for (int i = 0; i < bytesRead; i++) {
                    System.out.print((char) buf[i]);
                }
                bytesRead = inputStream.read(buf);
            }
        } catch (FileNotFoundException e) {
            e.printStackTrace();
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
    }
}
